<?php $pageParameter = pc_variable("pageParameter");
$pages = pc_variable("pages");
$currentPage = pc_variable("currentPage");
$uri = $_SERVER["REQUEST_URI"];
if(Pageley_Util_String::contains($uri, "?")) {
    if(!Pageley_Util_String::contains($uri, $pageParameter . "=")) {
    	$uri .= "&" . $pageParameter . "=0";
    }
} else {
    $uri .= "?" . $pageParameter . "=0";
} ?>
<div class="paging">
    <p class="currentPage"><?php pc_echo(pc_message("common.paging.page") . " " . $currentPage); ?></p> 
    <?php if($currentPage > 1) { 
        $pageUri = preg_replace("/" . $pageParameter . "=(\d+)/i", $pageParameter . "=" . 1, $uri); ?>
    	<a href="<?php pc_echo($pageUri)?>"><?php pc_echo(pc_message("common.paging.first")); ?></a>
    	<?php $pageUri = preg_replace("/" . $pageParameter . "=(\d+)/i", $pageParameter . "=" . ($currentPage - 1), $uri); ?>
        | <a href="<?php pc_echo($pageUri)?>"><?php pc_echo(pc_message("common.paging.previous")); ?></a>
    <?php }
    for($i = 1; $i <= $pages; $i++) { 
    	$pageUri = preg_replace("/" . $pageParameter . "=(\d+)/i", $pageParameter . "=" . $i, $uri);
    	if($i > 1 || $currentPage > 1) { ?>|<?php }
    	if($i != $currentPage) { ?>
            <a href="<?php pc_echo($pageUri)?>"><?php pc_echo($i); ?></a>
        <?php } else { ?>
            <?php pc_echo($i); ?>
        <?php }
    }
    if($currentPage < $pages) { 
        $pageUri = preg_replace("/" . $pageParameter . "=(\d+)/i", $pageParameter . "=" . $pages, $uri); ?>
        | <a href="<?php pc_echo($pageUri)?>"><?php pc_echo(pc_message("common.paging.next")); ?></a>
        <?php $pageUri = preg_replace("/" . $pageParameter . "=(\d+)/i", $pageParameter . "=" . ($currentPage + 1), $uri); ?>
        | <a href="<?php pc_echo($pageUri)?>"><?php pc_echo(pc_message("common.paging.last")); ?></a>
    <?php } ?>
</div>
